'use strict';

/* Controllers */

app
// Flot Chart controller
    .controller('fetureHistoryCtrl', ['$scope', '$modal', '$http', '$stateParams', '$rootScope', '$timeout', '$filter', function ($scope, $modal, $http, $stateParams, $rootScope, $timeout, $filter) {
        $rootScope.clean($scope.app)
        $scope.info = {};
        $scope.info.features = [];
        $scope.info.id = "";
        $scope.info.selectFeature = {};
        //功能点版本记录
        $scope.info.history = [];
        $scope.info.selectVersion = null;
        $scope.info.version = {};

        $scope.onChange = function () {
            $scope.info.history = [];
            $scope.info.selectVersion = null;
            $scope.info.version = {};
            //查询功能点历史
            $http.get(matrix_product_url + '/feature/getFeatureHistory?feature_id=' + $scope.info.selectFeature.id).success(function (data) {
                $scope.info.history = data.data;
            });
            // $scope.info.history = [{
            //     "featureId": "featureId1",
            //     "featureName": "featureName1",
            //     "version": "V1.1",
            //     "attr_config_id": "CFG2018010817391900004",
            //     "reqId": "",
            //     "reqName": "reqName1",
            //     "createTime": "2017-01-01 00:00:00"
            // }, {
            //     "featureId": "featureId2",
            //     "featureName": "featureName2",
            //     "version": "V1.2",
            //     "attr_config_id": "CFG2018010815321100015",
            //     "reqId": "",
            //     "reqName": "reqName2",
            //     "createTime": "2017-01-01 00:00:10"
            // }]
        }

        $scope.getList = function () {
            $http.get(matrix_product_url + '/feature/getFeature?withAttr=0').success(function (data) {
                $scope.info.features = data.data;
                angular.forEach($scope.info.features, function (f) {
                    f.show = f.path + '/' + f.featureName;
                });
                if ($scope.info.features.length > 0) {
                    $scope.info.selectFeature = $scope.info.features[0];
                    $scope.onChange();
                }
            });
        };
        $scope.getList();

        $scope.trClick = function (version) {
            if (!version.trCheck || version.trCheck == undefined) {
                $scope.info.selectVersion = version;
                for (var i in $scope.info.history) {
                    $scope.info.history[i].trCheck = false;
                    $scope.info.history[i].color = "";
                }
                version.trCheck = true;
                version.color = "sky";
                $scope.getConfigInfo();
            } else {
                $scope.info.selectVersion = null;
                version.trCheck = false;
                version.color = "";
            }
        }
        $scope.getConfigInfo = function () {
            $scope.info.version = {};
            $http.get(matrix_product_url + '/config/get?configId=' + $scope.info.selectVersion.attrConfigId).success(function (data) {
                if (data.code == '0') {
                    $scope.info.version = data.data.kvmap;
                }
            });
        }
    }]);